<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch">
      <el-form-item label="邮箱:" prop="email">
        <el-input
          size="mini"
          v-model="queryParams.email"
          placeholder="请输入邮箱"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="昵称:" prop="nickname">
        <el-input
          size="mini"
          v-model="queryParams.nickname"
          placeholder="请输入昵称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="姓名:" prop="firstName">
        <el-input
          size="mini"
          v-model="queryParams.firstName"
          placeholder="请输入昵称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="邀请码:" prop="inviteCode">
        <el-input
          size="mini"
          v-model="queryParams.inviteCode"
          placeholder="请输入邀请码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户类型:" prop="isVip">
        <el-select v-model="queryParams.isVip" placeholder="请选择用户类型" clearable size="mini">
          <el-option key="0" label="普通用户" value="0"/>
          <el-option key="1" label="会员用户" value="1"/>
        </el-select>
      </el-form-item>
      <el-form-item label="注册时间:">
        <el-date-picker
          v-model="dateRange"
          style="width: 240px"
          format="yyyy-MM-dd"
          value-format="timestamp"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :default-time="['00:00:00', '23:59:59']"
          size="mini"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="dataList">
      <el-table-column label="编号" align="center" prop="userNo" key="userNo"/>
      <el-table-column label="邮箱" align="center" prop="email" key="email"/>
      <el-table-column label="昵称" align="center" prop="nickname" key="nickname"/>
      <el-table-column label="姓氏" align="center" prop="lastName" key="lastName"/>
      <el-table-column label="名字" align="center" prop="firstName" key="firstName"/>
      <el-table-column label="性别" align="center" prop="sex" key="sex">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.sex"/>
        </template>
      </el-table-column>
      <el-table-column label="邀请码" align="center" prop="inviteCode" key="inviteCode"/>
      <el-table-column label="加密资产" align="center" prop="cryptoSum" key="cryptoSum"/>
      <el-table-column label="法定资产" align="center" prop="fiatSum" key="fiatSum"/>
      <el-table-column label="银行卡数" align="center" prop="cardSum" key="cardSum"/>
      <el-table-column label="用户类型" align="center" prop="isVip" key="isVip">
        <template slot-scope="scope">
          <el-tag type="primary" v-if="scope.row.isVip === '1'">会员用户</el-tag>
          <el-tag type="info" v-else>普通用户</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status" key="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.member_account_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="注册时间" align="center" prop="createTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="推荐用户数量" align="center" prop="recommendCount" key="recommendCount">
        <template slot-scope="scope">
          <el-button
            type="text"
            @click="goRecommendMemberList(scope.row)"
          >
            {{ scope.row.recommendCount }}
          </el-button>
        </template>
      </el-table-column>
      <el-table-column label="有效用户数量" align="center" prop="effectiveCount" key="effectiveCount">
        <template slot-scope="scope">
          <el-button
            type="text"
            @click="goRecommendMemberList(scope.row,'1')"
          >
            {{ scope.row.effectiveCount }}
          </el-button>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleInfo(scope.row)"
            v-hasPermi="['system:member:query']"
          >详情
          </el-button>
          <el-button
            v-if="scope.row.status === '0'"
            size="mini"
            type="text"
            @click="prohibitHandle(scope.row)"
            v-hasPermi="['system:member:prohibit']"
          >禁用
          </el-button>
          <el-button
            v-if="scope.row.status === '1'"
            size="mini"
            type="text"
            @click="liftHandle(scope.row)"
            v-hasPermi="['system:member:lift']"
          >解除禁用
          </el-button>
          <el-button
            size="mini"
            type="text"
            @click="moneyRefresh(scope.row)"
            v-hasPermi="['system:member:moneyRefresh']"
          >资产刷新
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <member-detail ref="member-detail"/>
    <recommend-member-list ref="recommend-member-list"/>
  </div>
</template>
<script>
import {pageList, prohibit, refreshMoney} from '@/api/triones/interlaceMember'
import memberDetail from "@/views/triones/member/memberUser/memberDetail";
import recommendMemberList from "@/views/triones/member/memberUser/recommendMemberList.vue";

export default {
  name: "index",
  components: {recommendMemberList, memberDetail},
  dicts: ['sys_user_sex', 'member_account_status'],
  data() {
    return {
      loading: false,
      showSearch: true,
      dateRange: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        email: undefined,
        nickname: undefined,
        firstName: undefined,
        inviteCode: undefined,
        isVip: undefined
      },
      dataList: [],
      total: 0,
      detailOpen: false,
      detail: {
        cryptoWalletList: [],
        plasticCardCount: {},
        virtualCardCount: {}
      }
    }
  },
  created() {
    this.getList();
  },
  methods: {
    getList() {
      this.loading = true;
      this.addDateRange(this.queryParams, this.dateRange);
      pageList(this.queryParams).then(res => {
        this.dataList = res.rows;
        this.total = res.total;
        this.loading = false;
      })
    },
    /** 检索 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 禁用 */
    prohibitHandle(row) {
      const id = row.id;
      this.$modal.confirm('是否确认禁用邮箱为"' + row.email + '"的用户？').then(function () {
        return prohibit(id, '1');
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("操作成功！");
      }).catch(() => {
      });
    },
    /** 解除禁用 */
    liftHandle(row) {
      const id = row.id;
      this.$modal.confirm('是否确认解除对邮箱为"' + row.email + '"用户的禁用？').then(function () {
        return prohibit(id, '0');
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("操作成功！");
      }).catch(() => {
      });
    },
    /** 用户详情 */
    handleInfo(row) {
      this.$refs["member-detail"].show(row.id);
    },
    goRecommendMemberList(row, isEffective) {
      this.$refs["recommend-member-list"].show(row.id, isEffective);
    },
    /** 资产刷新 */
    moneyRefresh(row) {
      this.$modal.confirm('是否确认刷新邮箱为"' + row.email + '"的用户资产？').then(function () {
        refreshMoney(row.id).then(() => {
          this.getList();
          this.$modal.msgSuccess("操作成功！");
        });
      })
    }
  }
}
</script>

<style scoped lang="scss">
.el-tooltip {
  overflow: hidden;
  display: -webkit-box;
  text-overflow: ellipsis;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  white-space: normal;
}
</style>
